package com.eliza.demo.qq.activity

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.eliza.demo.R
import com.eliza.library.model.QQUser


/*-*- coding:utf-8 -*-
 * @Author  : debi
 * @Time    : 5/1/22
 * @Software: Android Studio
 */
class QQAdapter : RecyclerView.Adapter<QQAdapter.QQAdapterHolder> {
    lateinit var qqUserList: List<QQUser>
    constructor(qqUserList: List<QQUser>) : super() {
        this.qqUserList = qqUserList
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QQAdapter.QQAdapterHolder {
        val root: View =
            LayoutInflater.from(parent.context)
                .inflate(
                    R.layout.fragment_qq_register_item,
                    parent,
                    false
                )
        return QQAdapter.QQAdapterHolder(root)
    }

    override fun onBindViewHolder(holder: QQAdapter.QQAdapterHolder, position: Int) {
        val qqUser: QQUser = qqUserList.get(position)
        holder.cName.text = qqUser.name ?: ""
        holder.cPwd.text = qqUser.pwd ?: ""
    }

    override fun getItemCount(): Int = qqUserList.size

    class QQAdapterHolder(val itemView: View) :
        RecyclerView.ViewHolder(itemView) {
        var cName = itemView.findViewById<TextView>(R.id.qq_db_show_name)
        var cPwd = itemView.findViewById<TextView>(R.id.qq_db_show_pwd)
    }
}